package guoanmaker.operator.business.controller;


import guoanmaker.operator.business.model.InRoundPhone;
import guoanmaker.operator.business.model.OperatorRoundPhoto;
import guoanmaker.operator.business.model.OperatorRoundPhotoApp;
import guoanmaker.operator.business.service.OperatorRoundPhotoServiceInterface;
import guoanmaker.operator.helper.common.AjaxJson;
import guoanmaker.operator.helper.common.abstractobj.ApiController;
import io.swagger.annotations.ApiOperation;

import java.util.Date;
import java.util.List;

import org.springframework.web.bind.annotation.*;

/**
 *  
 *
 * @author huZhaoyu 
 * @ClassName: OperatorRoundPhotoController
 * @Description: OperatorRoundPhotoController 
 * @date 2017/6/28 上午10:09 
 */
@RestController
@RequestMapping(ApiController.OPERATOR_ROUNDPHOTO_URL)
public class OperatorRoundPhotoController {
    private final AjaxJson ajaxJson;
    private final OperatorRoundPhotoServiceInterface operatorRoundPhotoServiceInterface;

    public OperatorRoundPhotoController(AjaxJson ajaxJson, OperatorRoundPhotoServiceInterface operatorRoundPhotoServiceInterface) {
        this.ajaxJson = ajaxJson;
        this.operatorRoundPhotoServiceInterface = operatorRoundPhotoServiceInterface;
    }

    /** 
    * @Title: saveRoundPhoto 
    * @Description: 新增/修改轮播图 
    * @param: OperatorRoundPhoto   
    * @return AjaxJson    
    * @throws 
    */
    @ApiOperation(value = "保存轮播图", notes = "新增/修改轮播图")
    @PostMapping(value = "saveRoundPhoto")
    public AjaxJson saveRoundPhoto(@RequestBody InRoundPhone inRoundPhone) {
    	try{
    	List<OperatorRoundPhoto> operatorRoundPhotoList=inRoundPhone.getOperatorRoundPhotos();
    	operatorRoundPhotoServiceInterface.delectAllBycitycode(inRoundPhone.getCityId());
    	for(OperatorRoundPhoto orp:operatorRoundPhotoList){
    		orp.setCreateDate(new Date());
    		orp.setCityCode(inRoundPhone.getCityId());
    		operatorRoundPhotoServiceInterface.saveRoundPhoto(orp);
    		
    	}
    	ajaxJson.setSuccess(true).setStatus(200).setData(null);
	}catch(Exception e){
		ajaxJson.setSuccess(false).setStatus(250).setData(null);
	}
    	 return ajaxJson;
    }

    /** 
     * @Title: deleteRoundPhotoById
     * @Description: 根据Id删除轮播图
     * @param: String id  
     * @return AjaxJson 
     * @throws 
     */
    @ApiOperation(value = "删除轮播图", notes = "根据Id删除轮播图")
    @DeleteMapping(value = "delete/{id}")
    public AjaxJson deleteRoundPhotoById(@PathVariable(value = "id") String id) {
        operatorRoundPhotoServiceInterface.deleteRoundPhotoById(id);
        return ajaxJson.setSuccess(true).setStatus(200).setData("数据删除成功!");
    }

    /**
     * @return OperatorRoundPhoto    
     * @Title: getRoundPhotoById 
     * @Description: 根据Id查询轮播图
     * @param: String id   
     * @throws 
     */
    @ApiOperation(value = "根据Id查询轮播图", notes = "根据Id查询轮播图")
    @GetMapping(value = "getRoundPhotoById")
    public AjaxJson getRoundPhotoById(@RequestParam(value = "id") String id) {
        return ajaxJson.setSuccess(true).setStatus(200).setData(operatorRoundPhotoServiceInterface.getRoundPhotoById(id));
    }

    /**
     * @return AjaxJson   
     * @Title: getAllRoundPhoto
     * @Description: 查找所有轮播图 
     * @throws 
     */
    @ApiOperation(value = "查找所有轮播图", notes = "查找所有轮播图")
    @GetMapping(value = "getAllRoundPhoto")
    public AjaxJson getAllRoundPhoto() {
        return ajaxJson.setSuccess(true).setStatus(200).setData(operatorRoundPhotoServiceInterface.getAllRoundphoto());
    }

   /**
    * 
   * @Title: getAllRoundPhotoByPage 
   * @Description: TODO(这里用一句话描述这个方法的作用) 
   * @param cityCode
   * @return    设定文件 
   * @return AjaxJson    返回类型 
   * @throws 
    */
    @ApiOperation(value = "根据城市查询轮播图列表", notes = "根据城市查询轮播图列表")
    @GetMapping(value = "getAllRoundPhotoByPage")
    public AjaxJson getAllRoundPhotoByPage(String cityCode) {
        return ajaxJson.setSuccess(true).setStatus(200).setData(operatorRoundPhotoServiceInterface.getAllRoundPhotoByPage(cityCode));
    }

    /**
     * @return AjaxJson   
     * @Title: getAllRoundPhotoByWeightAndPage 
     * @Description: 按权重排序分页查询轮播图 
     * @param: Integer page 页码
     * @param: Integer size 条数
     * @throws 
     */
    @ApiOperation(value = "分页查询轮播图", notes = "分页查询轮播图")
    @GetMapping(value = "getAllRoundPhotoByWeightAndPage")
    public AjaxJson getAllRoundPhotoByWeightAndPage(@RequestParam(value = "page", defaultValue = "0") Integer page,
                                           @RequestParam(value = "size", defaultValue = "10") Integer size) {
        return ajaxJson.setSuccess(true).setStatus(200).setData(operatorRoundPhotoServiceInterface.getAllRoundPhotoByWeightAndPage(page, size));
    }
    
    
    @ApiOperation(value = "查找所有PC轮播图", notes = "查找所有PC轮播图")
    @PostMapping(value = "getAllRoundPhotoPc")
    public AjaxJson getAllRoundPhotoPc(String  cityId) {
    	try{
    	List<OperatorRoundPhoto>  rpspps=operatorRoundPhotoServiceInterface.getAllRoundPhotoByPage(cityId);
    	ajaxJson.setSuccess(true).setStatus(200).setData(rpspps);
    	}catch(Exception e){
    		ajaxJson.setSuccess(true).setStatus(250).setData(null);
    	}
        return ajaxJson;
    }

}
